package com.megvii.koala.net;

import android.content.Context;

import com.megvii.corelib.net.MegviiHttpManager;
import com.megvii.koala.constance.Constant;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by linyue on 15/12/20.
 */
public class KoalaHttpManager extends MegviiHttpManager
{
    private String cookie;

    private String userAgent;

    public KoalaHttpManager(Context context)
    {
        super(context);
    }

    @Override
    protected Map<String, String> getHeaders()
    {
        Map<String, String> headers = new HashMap<>();
        if (cookie != null)
        {
            headers.put(HttpConstance.HEADER_KEY_COOKIE, cookie);
        }
        if (userAgent != null)
        {
            headers.put(HttpConstance.HEADER_KEY_USER_AGENT, userAgent);
        }
        return headers;
    }

    @Override
    public void onReceiveHeader(String key, String value)
    {
        if (key.equals(HttpConstance.HEADER_KEY_SET_COOKIE))
        {
            setCookie(value);
        }
    }

    public String getCookie()
    {
        return cookie;
    }

    public void setCookie(String cookie)
    {
        this.cookie = cookie;
    }

    public String getUserAgent()
    {
        return userAgent;
    }

    public void setUserAgent(String userAgent)
    {
        this.userAgent = userAgent;
    }
}
